<template>
  <div class="common-layout">
    <el-container>
      <el-header class="header">Header</el-header>
      <el-container class="container">
        <el-aside width="200px" class="aside">Aside</el-aside>
        <el-main class="main">
          <el-row :gutter="20">
            <el-col :span="18">
              <el-row :gutter="20">
                <el-col :span="6">
                  <div class="grid-content ep-bg-purple" />
                </el-col>
                <el-col :span="6">
                  <div class="grid-content ep-bg-purple" />
                </el-col>
                <el-col :span="6">
                  <div class="grid-content ep-bg-purple" />
                </el-col>
                <el-col :span="6">
                  <div class="grid-content ep-bg-purple" />
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
                  <div class="grid-content ep-bg-purple" />
                </el-col>
                <el-col :span="12">
                  <div
                    class="grid-content ep-bg-purple"
                    id="main"
                    style="background: #fff"
                  />
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="24">
                  <div
                    class="grid-content ep-bg-purple"
                    id="main2"
                    style="background: #fff"
                  />
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="6">
              <div class="grid-content ep-bg-purple-light" />
            </el-col>
          </el-row>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted } from "vue";
import * as echarts from "echarts";

import product from "@/mock/product";

export default defineComponent({
  setup() {
    onMounted(() => {
      init1();
      init2();
    });

    onMounted(async () => {
      const res = await product.getData({
        pageSize: 10,
        currentPage: 1,
      });
      console.log(res);
    });

    const init1 = () => {
      const main = document.getElementById("main");
      // eslint-disable-next-line
      let myChart: any;
      if (main) {
        // 基于准备好的dom，初始化echarts实例
        myChart = echarts.init(main);
        // 绘制图表
        myChart.setOption({
          title: {
            text: "周访问数",
            padding: 20,
          },
          legend: {
            right: "10%",
            top: "middle",
            orient: "vertical",
            itemGap: 20,
          },
          series: [
            {
              type: "pie",
              radius: [20, 120],
              center: ["40%", "50%"],
              roseType: "area",
              itemStyle: {
                borderRadius: 8,
              },
              data: [
                { value: 40, name: "周1" },
                { value: 38, name: "周2" },
                { value: 32, name: "周3" },
                { value: 30, name: "周4" },
                { value: 28, name: "周5" },
                { value: 26, name: "周6" },
                { value: 30, name: "周7" },
              ],
            },
          ],
        });
      }

      window.addEventListener("resize", () => {
        myChart.resize();
      });
    };
    const init2 = () => {
      const main2 = document.getElementById("main2");
      // eslint-disable-next-line
      let myChart: any;
      if (main2) {
        // 基于准备好的dom，初始化echarts实例
        myChart = echarts.init(main2);
        // 绘制图表
        myChart.setOption({
          title: {
            text: "年访问数",
          },
          tooltip: {
            trigger: "axis",
          },
          grid: {
            left: "6%",
            right: "8%",
            bottom: "6%",
            containLabel: true,
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
          },
          yAxis: {
            type: "value",
          },
          series: [
            {
              name: "Email",
              type: "line",
              smooth: true,
              data: [120, 132, 101, 134, 90, 230, 210],
            },
            {
              name: "Union Ads",
              type: "line",
              smooth: true,
              data: [220, 182, 191, 234, 290, 330, 310],
            },
            {
              name: "Video Ads",
              type: "line",
              smooth: true,
              data: [150, 232, 201, 154, 190, 330, 410],
            },
            {
              name: "Direct",
              type: "line",
              smooth: true,
              data: [320, 332, 301, 334, 390, 330, 320],
            },
            {
              name: "Search Engine",
              type: "line",
              smooth: true,
              data: [320, 232, 301, 434, 590, 430, 220],
            },
          ],
        });
      }

      window.addEventListener("resize", () => {
        myChart.resize();
      });
    };

    // const data = [
    //   {
    //     date: "Mon",
    //     data: {
    //       "Email": 120,
    //       "Union Ads": 150,
    //       "xxx": 220
    //     }
    //   },
    //   {
    //     date: "Tus",
    //     data: {
    //       "Email": 220,
    //       "Union Ads": 170,
    //       "xxx": 220
    //     }
    //   }
    // ]
  },
});
</script>

<style lang="less">
* {
  margin: 0;
  padding: 0;
}
.header {
  background: lightblue;
}
.container {
  min-height: calc(100vh - 60px);
}
.aside {
  background: lawngreen;
}
.main {
  background: #eee;
}

.el-row {
  margin-bottom: 20px;
}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  background: lightcoral;
  height: 300px;
}
</style>
